import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Random random = new Random();
        int numberToGuess = random.nextInt(100) + 1; // 生成1到100之间的随机数
        Scanner scanner = new Scanner(System.in);
        int numberOfTries = 0;
        int guess;

        System.out.println("欢迎来到猜数字游戏！");
        System.out.println("我已经想好了一个1到100之间的数字，你有10次机会来猜这个数字。");
        System.out.println("让我们开始吧！");

        while (numberOfTries < 10) {
            System.out.print("请输入你的猜测: ");
            guess = scanner.nextInt();
            numberOfTries++;

            if (guess < numberToGuess) {
                System.out.println("你猜的数字小了！");
            } else if (guess > numberToGuess) {
                System.out.println("你猜的数字大了！");
            } else {
                System.out.println("恭喜你，猜对了！你总共猜了 " + numberOfTries + " 次。");
                break;
            }
        }

        if (guess != numberToGuess) {
            System.out.println("很遗憾，你没有在规定的次数内猜对数字，正确答案是 " + numberToGuess);
        }

        scanner.close();
    }
}
